package com.xxl.job.executor.core.utils;


import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class ConfigUtil {

    private static ConfigUtil instance;

    private static Properties properties = new Properties();

    public static String HOST;
    public static Integer PORT;
    public static String USERNAME;
    public static String PASSWORD;
    public static String SRCFILE;
    public static String BAKFILE;
    public static String FTPFILE;

    private ConfigUtil(){
    }

    {
        InputStream is = ConfigUtil.class.getClassLoader().getResourceAsStream("application.properties");
        try {
            properties.load(is);
        } catch (IOException e) {
            e.printStackTrace();
        }
        this.HOST = FtpHost();
        this.PORT = FtpPort();
        this.USERNAME = FtpUsername();
        this.PASSWORD = FtpPassword();
        this.SRCFILE = ScanFilePath();
        this.BAKFILE = BakFilePath();
        this.FTPFILE = FtpFilePath();
    }

    public static ConfigUtil getInstance(){
        if (instance == null){
            instance = new ConfigUtil();
        }
        return instance;
    }

    private String FtpHost(){
        String host = properties.getProperty("ftp.host");
        return host;
    }

    private Integer FtpPort() {
        Integer port = Integer.valueOf(properties.getProperty("ftp.port"));
        return port;
    }

    private String FtpUsername() {
        String username = properties.getProperty("ftp.username");
        return username;
    }

    private String FtpPassword() {
        String password = properties.getProperty("ftp.password");
        return password;
    }

    private String ScanFilePath() {
        String scanfilepath = properties.getProperty("src.filepath");
        return scanfilepath;
    }

    private String BakFilePath() {
        String bakfilepath = properties.getProperty("bak.filepath");
        return bakfilepath;
    }

    private String FtpFilePath() {
        String ftpfilepath = properties.getProperty("ftp.filepath");
        return ftpfilepath;
    }
}
